// pages/homePage/homePage.js
//获取应用实例
const app = getApp()
const util = require('../../utils/util.js')
var that;
var istap = true;
Page({

  /**
   * 页面的初始数据
   */
  data: {
    singleNavWidth: 110,
    currentTab: 0,
    navScrollLeft: 0,
    navData: [{
      'dicName': '出境旅游'
    }, {
      'dicName': '国内旅游'
    }, {
      'dicName': '主题旅游'
    }, {
      'dicName': '其他旅游'
    }]
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    that = this;
    var pageoneList = [];
    var bannerList = [];
    for (var i = 0; i < 8; i++) {
      var dict = {
        'imgurl': '../imagesource/classification0' + (i + 1) + '.png',
        'dicName': '出境游'
      }
      pageoneList.push(dict);
      bannerList.push({
        'pic': '../imagesource/banner1.png'
      })
    }
    that.setData({
      pageone: pageoneList,
      bannerList: bannerList
    })
  },
  switchNav(event) {
    if (istap) {
      istap = false;
      setTimeout(function() {
        istap = true
      }, 300)
    } else {
      return;
    }

    var cur = event.currentTarget.dataset.current;

    //tab选项居中                            
    this.setData({
      navScrollLeft: (cur - 2) * that.data.singleNavWidth
    })
    if (this.data.currentTab == cur) {
      return false;
    } else {
      this.setData({
        currentTab: cur
      })
    }
  },
  switchTab(event) {
    if (istap) {
      istap = false;
      setTimeout(function() {
        istap = true
      }, 300)
    } else {
      return;
    }
    var cur = event.detail.current;
    this.setData({
      currentTab: cur,
      navScrollLeft: (cur - 2) * that.data.singleNavWidth
    });
  },
  //跳转Page
  gotoPage: function(e) {
    var index = e.currentTarget.index
    wx.navigateTo({
      url: '/pages/home_listPage/home_listPage',
    })
  }

})